<template>
  <div>
<h1>登录界面</h1>
<table>
<tr>
  <td>账号：</td>
  <td><input type="text" v-model="state.ZhangHao"></td>
</tr>
<tr>
  <td>密码：</td>
  <td><input type="password" v-model="state.MiMa"></td>
</tr>
<tr>
  <td></td>
  <td><input type="button" value="登录" @click="denglu"></td>
</tr>
</table>
  </div>
</template>

<script setup lang="ts">
import {reactive,toRefs} from 'vue'
import axios from 'axios'
import {useRoute,useRouter} from 'vue-router'
const route=useRoute()
const router=useRouter()

let data=reactive({
  state:{
     ZhangHao:'',
     MiMa:''
  }
})

let {state}=toRefs(data)

const denglu=()=>{
  axios({
    url:'/api/User/GetRegister',
    method:'get',
    params:state.value
  })
  .then(res=>{
    if(res.data.data==1){
      alert('登录成功');
      router.push("/display");
    } else if(res.data.data==2){
      router.push("/show");
    } else if(res.data.data==-1){
       alert('用户名不存在');
       return;
    }
    else{
      alert('用户名或密码错误');
      return;
    }
  })
  .catch(err=>{
    console.log(err);
  })
}
</script>

<style scoped>

</style>